package com.dotndot.controller.network.resData;

import com.google.gson.*;

public class Response
{
    public enum Status
    {
        OK,
        ERROR,
        WARNING
    }

    public enum Code
    {
        S000,
        W001, // RET_EMAIL_UNAVAILABLE_FAIL
        W002, // RET_PASSWORD_UNAVAILABLE_FAIL
        E001, // RET_LOGIN_NOT_EXIST_EMAIL
        E002, // RET_LOGIN_DIFFERENT_PASSWORD
        E003
        // RET_JOIN_EMAIL_DUPLICATED
    }

    public enum Message
    {
        /* Common */
        RET_EMAIL_UNAVAILABLE,
        RET_PASSWORD_UNAVAILABLE,

        /* Version */
        RET_VERSION_SUCCESS,

        /* Login */
        RET_LOGIN_SUCCESS,
        RET_LOGIN_NOT_EXIST_EMAIL,
        RET_LOGIN_DIFFERENT_PASSWORD,

        /* Join */
        RET_JOIN_SUCCESS,
        RET_JOIN_EMAIL_DUPLICATED,

        /* Story */
        RET_STORY_GET_LIST_SUCCESS,
        RET_STORY_GET_LIST_FAIL,
        RET_STORY_ADD_ITEM_SUCCESS,
    }

    public Status status;
    public Code code;
    public Message message;
    public Object object;

    public Response( Status status, Code code, Message message )
    {
        this.status = status;
        this.code = code;
        this.message = message;
    }

    public Response( Status status, Code code, Message message, Object object )
    {
        this.status = status;
        this.code = code;
        this.message = message;
        this.object = object;
    }

    public String toJson()
    {
        Gson gson = new Gson();
        String json = gson.toJson(this);
        return json;
    }

    public static Response constructFromJson( String json )
    {
        Gson gson = new Gson();
        return gson.fromJson(json, Response.class);
    }
}
